package myServlet;

import Smt.ServerImp.BillServerImp;
import Smt.ServerImp.SupplierServerImp;
import Smt.Util.Bill;
import Smt.Util.Supplier;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

@SuppressWarnings("serial")
public class BillRead extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		BillServerImp bsi = new BillServerImp();
		String update = request.getParameter("Update");
		if (update != null) {
			request.setAttribute("update", update);
		}
		String add = request.getParameter("add");
		if (add != null) {
			request.setAttribute("add", 3);
		}
		String error = (String) request.getAttribute("error");
		if (error != null) {
			request.setAttribute("error", error);
		}
		HttpSession session = request.getSession();

		String yeshu = request.getParameter("num");//作为当前页
		if (yeshu == null)
			yeshu = "1";
		int ye = Integer.parseInt(yeshu);//当前页
		int i = 3;//每页内容
		String productName = (String) session.getAttribute("productName");//商品名称
		String pay = (String) session.getAttribute("payStatus");//账单状态
		if (productName == null) {
			productName = "";
		}
		if (pay == null) {
			pay = "";
		}
		String product = request.getParameter("productName");
		String payss = request.getParameter("payStatus");
		if (product == null) {
			product = "";
		}
		if (payss == null) {
			payss = "";
		}
		String b = request.getParameter("b");
		if (b == null) {
			productName = product;
			pay = payss;
		}
		session.setAttribute("productName", productName);
		session.setAttribute("payStatus", pay);
		ArrayList<Bill> list = bsi.PayNameRead(ye, i, pay, productName);
		int yenum = bsi.getYenum();//总页数
		if (list.size() == 0) {
			request.setAttribute("nulls", "当前没有什么数据可以显示.");
		}
		SupplierServerImp ssi = new SupplierServerImp();
		ArrayList<Supplier> slist = ssi.getSupplier();
		request.setAttribute("slist", slist);
		request.setAttribute("list", list);
		request.setAttribute("yenum", yenum);//总页数
		request.setAttribute("num", yeshu);//当前页
		request.getRequestDispatcher("Bill_list.jsp").forward(request, response);

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doGet(request, response);

	}
}
